﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media.Animation;
using System.Windows;
using System.Windows.Controls;

namespace MigratorUI.RenderEngine
{
    class MovementAnimation : Animation
    {
        public MovementAnimation(Sprite sprite,bool isRepeatAnimation,Point toPosition) : base(sprite,isRepeatAnimation) {
            this.toPosition = toPosition;
            this.isRepeatAnimation = false;
        }
        public override void RunAnimation()
        {
            DoubleAnimation animationX = new DoubleAnimation(base.Sprite.Position.X, toPosition.X, new Duration(TimeSpan.FromSeconds(2)));
            DoubleAnimation animationY = new DoubleAnimation(base.Sprite.Position.Y, toPosition.Y, new Duration(TimeSpan.FromSeconds(2)));
            animationX.AutoReverse = false;
            animationY.AutoReverse = false;
            animationX.Completed += new EventHandler(MoveYCompletedHandler);
            animationY.Completed += new EventHandler(MoveXCompletedHandler);
            base.Sprite.GetDrawableItem().BeginAnimation(Canvas.LeftProperty, animationX);
            base.Sprite.GetDrawableItem().BeginAnimation(Canvas.TopProperty, animationY);
        }

        private void MoveXCompletedHandler(object sender, EventArgs e)
        {
            ((AnimationClock)sender).Controller.Remove();
            base.AnimationCompleted();
        }
        
        private void MoveYCompletedHandler(object sender, EventArgs e)
        {
            ((AnimationClock)sender).Controller.Remove();
        }
        protected override void CreateShape()
        {
        }

        private Point toPosition; 
    }
}
